package org.dbi.logger;


import java.util.Calendar;
import java.util.logging.*;
import java.text.SimpleDateFormat;

/**
 * Deze class formateert de opmaak van de log file
 * @author Walter
 */
public class LoggerFormatter extends Formatter {
	/**
	 * Constructor
	 */
	public LoggerFormatter() {
		super();
	}

	/**
	 * Deze methode is van Formatter class en maakt de log file op. <br />
	 * De opmaak ziet er als volgt uit: <br />
	 * <datum>	<level>		<bericht>
	 * 
	 * @param LogRecord Het LogRecord object van wat er gelogged moet worden.
	 * @retrun De string die word opgeslagen in de log file.
	 */
	public String format(LogRecord logRecord) {
		StringBuffer stringBuffer = new StringBuffer();
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(logRecord.getMillis());
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
		
		stringBuffer.append(dateFormat.format(calendar.getTime()));
		stringBuffer.append("\t");

		stringBuffer.append(logRecord.getSourceClassName());
		stringBuffer.append("\t");

		stringBuffer.append(logRecord.getSourceMethodName());
		stringBuffer.append("\t");
		
		stringBuffer.append(logRecord.getLevel().getName());
		stringBuffer.append("\t");
		 
		stringBuffer.append(this.formatMessage(logRecord));
		stringBuffer.append("\n");

		if(logRecord.getThrown() != null) {
			stringBuffer.append(logRecord.getThrown().getStackTrace());
			stringBuffer.append("\n");
		}
		
		stringBuffer.append("================================");
		stringBuffer.append("\n");
		
		return stringBuffer.toString();
	}
}
